package cn.sciento.farm.devicemanager.gateway.downlink;

import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * User: wumu
 * Date: 1/17/18
 * Time: 6:04 PM
 * @author wumu
 */
public class DelayManager {
    //日志记录操作延时
    private final int OPERATE_DELAY_TIME = 1;

    //异步操作记录日志的线程池
    private ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3);

    private DelayManager() {
    }

     static DelayManager delayManager = new DelayManager();

    public static DelayManager getInstance() {
        return delayManager;
    }

    public void executeLog(TimerTask task) {
        executeLog(task, OPERATE_DELAY_TIME);
    }

    public void executeLog(TimerTask task, int time) {
        executor.schedule(task, time, TimeUnit.SECONDS);
    }
}